package com.unionx.yanlian.websocket;  

import java.util.concurrent.atomic.AtomicInteger;  

import javax.servlet.http.HttpServletRequest;  

import org.apache.catalina.websocket.StreamInbound;  
import org.apache.catalina.websocket.WebSocketServlet;  
  
public class HelloWebSocketServlet extends WebSocketServlet {  
    private static final long serialVersionUID = 1L;  
  
    private final AtomicInteger connectionIds = new AtomicInteger(0);  
  //跟平常Servlet不同的是，需要实现createWebSocketInbound，在这里初始化自定义的WebSocket连接对象
    @Override
    protected StreamInbound createWebSocketInbound(String subProtocol,HttpServletRequest request) {
        return new WebSocketMessageInbound(this.getUser(request));
    }
    public String getUser(HttpServletRequest request){
		return (String) request.getParameter("id");
	}
}  
